<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html><head>
<script type="text/javascript">

/**
 * 是否签收格式化
 */
function recFormatter(value, row, index) {
	var status = "-";
	switch(value){
	case '1' : status = "已签收"; break;
	case '2' : status = "未送货"; break;
	case '3' : status = ""; break;
	}
	return status;
}

function edit(id){
	var idx = layer.load();
	oWin = layer.open({type:2,shade: 0,maxmin:true,scrollbar:false,title:"edit",skin:"layui-layer-rim",area:["800px","600px"],content:"finance/accountJournal/detail/"+id,
		end:function(){
			$('#accountJournalTable').bootstrapTable('refresh');
			$('#accountJournalTable').bootstrapTable('resetView');
			}
	});
	layer.close(idx);
}

function remove(id){
	layer.confirm("确定删除此行？",function(){
		var idx = layer.load();
		$.ajax({
			url:"finance/accountJournal/delete/",
			method:"post",
			data:JSON.stringify({id:id}),
			dataType:"json",
			contentType: "application/json",
			complete:function(data){
				layer.close(idx);
				if(data.status==200&&data.responseText=="success"){
					$('#accountJournalTable').bootstrapTable("remove", {field:'id',values:[id]});
					layer.msg('SUCCESS!', {time:1000,icon: 1});
				}else{
					layer.alert("FAILURE!");
				}
			}
		});
	});
}
$(function(){
	$('#btn_add').on('click',function(){
		layer.open({type:2,shade: 0,maxmin:true,scrollbar:false,title:"add",skin:"layui-layer-rim",area:["800px","600px"],content:"finance/accountJournal/detail/"});
	});
});

$(function(){
	$('#criteria').on('click',function(){
		layer.open({type:2,shade: 0,maxmin:true,scrollbar:false,title:"Criteria",skin:"layui-layer-rim",area:["300px","400px"],content:"criteria.html"});
	})
});

var $table = $('#accountJournalTable');
	$(document).ready(function() {
		$table.bootstrapTable({
			toolbar:"#toolbar",
			showRefresh:true,
			striped:true,
			pagination:true,
			sidePagination: "server",
			pageList:PAGE_LIST,
			paginationLoop:false,
			method:"post",
			url:"finance/accountJournal/queryPagination",
			showColumns: true,
			showToggle:true,
		    columns: [
		    	{checkbox:true,align:"center",valign:"middle"},
				{field: 'name',title: '名称',align:"center",valign:"middle"},
				{field: 'deliverDate',title: '送货日期',align:"center",valign:"middle",formatter:dateFormatter},
				{field: 'standard',title: '规格',align:"center",valign:"middle"},
				{field: 'unit',title: '单位',align:"center",valign:"middle"},
				{field: 'num',title: '数量',align:"center",valign:"middle"},
				{field: 'price',title: '单价',align:"center",valign:"middle",formatter:function(value,row,index){return value/100}},
				{field: 'amount',title: '金额',align:"center",valign:"middle",formatter:function(value,row,index){return value/100}},
				{field: 'status',title: '是否签收',align:"center",valign:"middle",formatter:recFormatter},
				{field: 'dep',title: '所属部门',align:"center",valign:"middle"},
				{field: 'bill',title: '发票号',align:"center",valign:"middle"},
				{field: 'note',title: '备注',align:"center",valign:"middle"}
				]
		});
	});
	
	$(function () {
	  	$table.on('click-row.bs.table', function (e, row, $element) {
	    		$('.success').removeClass('success');
	    		$($element).addClass('success');
	  	});
	});
	
	$(function () {
		var $table = $('#accountJournalTable');
		$('#exportSelect').find('select').change(function () {
	    $table.bootstrapTable('refreshOptions', {
	      exportDataType: $(this).val()
	    });
	  });
	});
	
	$(function () {
		var $table = $('#accountJournalTable');
		$('#btn_export').click(function () {
	  	$table.tableExport({
	      type: 'excel',
	      escape: false
	    });
	  });
	});
</script>
</head><body>
	<div id="toolbar" class="btn-group">
		<button id="criteria" type="button">Cri</button>
		<div id="criterias"><button id="query" type="button">Query</button></div>
	</div>
<table id="accountJournalTable" data-show-export="true"></table>
</body></html>